package org.malred.hospital.controller;

import org.malred.hospital.common.R;

import org.malred.hospital.entity.TbOrder;
import org.malred.hospital.entity.TbOrder;
import org.malred.hospital.entity.TbOrder;
import org.malred.hospital.service.OrderService;
import org.malred.hospital.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController extends BaseController<TbOrder> {
    @Autowired
    private OrderService service;

    @Override
    public R<List<TbOrder>> findAll() {
        return R.success(service.list());
    }

    @Override
    public R<TbOrder> findById(Long id) {
        return R.success(service.getById(id));
    }

    @Override
    public R<TbOrder> insert(@RequestBody TbOrder dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("添加 [Order] 失败");
        }
    }

    @Override
    public R<TbOrder> update(@RequestBody TbOrder dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("修改 [Order] 失败");
        }
    }

    @Override
    public R<TbOrder> delete(Long id) {
        if (service.removeById(id)) {
            return R.success(null);
        } else {
            return R.error("删除 [Order] 失败");
        }
    }
}
